﻿using System;
using System.Collections.Generic;
using System.Diagnostics;

namespace Mac随机生成算法
{
    class Program
    {
        
        static void Main(string[] args)
        {
            int loopNum = 1;
            int generatorNum = 1000;
            int cnt = 0;
            Dictionary<string, string> macMap = new Dictionary<string, string>();
            for (int index = 0; index < loopNum; index++) {

                if (index % 100 == 0)
                    Console.WriteLine(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.fff") + " 第" + index.ToString() + "次");

                //if(macMap.Count > 0) macMap.Clear();

                for (int i = 0; i < generatorNum; i++) {

                    string macStr = MacGenerator.GeneratorMacString();
                    Debug.Print(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.fff") + "生成的MAC:" + macStr + "\r\n");
                    if (macMap.ContainsKey(macStr)) {

                        //System.Console.WriteLine(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.fff") + " 生成的MAC冲突:" + i.ToString() + "");
                        cnt++;
                        continue;
                    }
                    macMap.Add(macStr, macStr);
                }
            }

            Console.WriteLine("循环次数:" + loopNum.ToString());
            Console.WriteLine("单次生成数:" + generatorNum.ToString());
            Console.WriteLine("冲突次数:" + cnt.ToString());
            Console.WriteLine("冲突概率:万分之" + ((double)cnt / loopNum).ToString("f5"));
            
            Console.WriteLine("冲突次数:" + cnt.ToString());

        }
    }
}
